/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import Process.Branches;
import Process.InstallmentMonthlyDetail;
import Process.InstallmentMonthlyProcess;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Date;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author babman92
 */
public class InstallmentMonthlyOne extends javax.swing.JFrame {

    /**
     * Creates new form InstallmentMonthlyOne
     */
    final String Account;
    JPopupMenu popMenu;
    JMenuItem menuItem;

    public InstallmentMonthlyOne() {
        initComponents();
        Account = "";
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        SetSourceTable();
    }

    public InstallmentMonthlyOne(String Account) {
        this.Account = "C1011L0011";
    }

    private void SetSourceTable() {
        InstallmentMonthlyProcess Installment = new InstallmentMonthlyProcess();
        Vector data = Installment.getList(Account);
        Vector column = new Vector();
        column.addElement("CustomerID");
        column.addElement("RateInterestMoney");
        column.addElement("MoneyRoot");
        column.addElement("Total");
        column.addElement("PayDate");
        column.addElement("State");
        TableModel model = new DefaultTableModel(data, column);
        tblInstallment.setModel(model);
        //tblInstallment.setModel(model);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblInstallment = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txfSearch = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED), "Data"));
        jPanel1.setLayout(new java.awt.BorderLayout());

        tblInstallment.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tblInstallment.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblInstallmentMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblInstallment);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED), "Control"));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("Search by CustomerID");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(400, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(42, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblInstallmentMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblInstallmentMouseClicked
        // TODO add your handling code here:
        int RowIndex = tblInstallment.getSelectedRow();
        setPopupMenu(RowIndex);

    }//GEN-LAST:event_tblInstallmentMouseClicked

    private void setPopupMenu(final int RowIndex) {
        popMenu = new JPopupMenu();
        menuItem = new JMenuItem("View Details");
        popMenu.add(menuItem);
        menuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                String ID = tblInstallment.getModel().getValueAt(RowIndex, 0).toString();
                String RateMoney = tblInstallment.getModel().getValueAt(RowIndex, 1).toString();
                String MoneyRoot = tblInstallment.getModel().getValueAt(RowIndex, 2).toString();
                String Total = tblInstallment.getModel().getValueAt(RowIndex, 3).toString();
                String PayDate = tblInstallment.getModel().getValueAt(RowIndex, 4).toString();
                String State = tblInstallment.getModel().getValueAt(RowIndex, 5).toString();
                InstallmentMonthlyDetail Detail = new InstallmentMonthlyDetail();
                Detail.setCusID(ID);
                Detail.setPayDate(PayDate);
                Detail.setRateMoney(RateMoney);
                Detail.setRootMoney(MoneyRoot);
                Detail.setState(State);
                Detail.setTotal(Total);
                JOptionPane.showMessageDialog(null, Detail.getPayDate());
                InstallmentMonthlyDetails DetailsUI = new InstallmentMonthlyDetails();
                DetailsUI.setVisible(true);
                DetailsUI.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            }
        });
        tblInstallment.addMouseListener(new MouseAdapter() {

            public void mousePressed(MouseEvent me) {
                if (me.isPopupTrigger()) {
                    popMenu.show(me.getComponent(), me.getX(), me.getY());
                }
            }

            public void mouseReleased(MouseEvent Me) {
                if (Me.isPopupTrigger()) {
                    popMenu.show(Me.getComponent(), Me.getX(), Me.getY());
                }
            }
        });

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(InstallmentMonthlyOne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(InstallmentMonthlyOne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(InstallmentMonthlyOne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(InstallmentMonthlyOne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InstallmentMonthlyOne().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblInstallment;
    private javax.swing.JTextField txfSearch;
    // End of variables declaration//GEN-END:variables
}
